package org.whuims.pois.dao;

import org.whuims.pois.hibernate.BaseDao;
import org.whuims.pois.model.User;

import java.util.List;

/**
 * Created by zhongwei on 2014/5/16.
 */
public class UserDao {
    static BaseDao baseDao = new BaseDao();

    /**
     * 查找user，返回list
     *
     * @return
     */
    public List<User> select() {
        List<User> list = baseDao.find("from User");
        return list;
    }

    /**
     * 根据id查找User一个对象，返回一个TopicC对象
     *
     * @param id
     * @return
     */
    public static User select(long id) {
        User bean = (User) baseDao.getByPk(User.class, id);
        return bean;
    }

    public User findByName(String userName) {
        List<User> list = baseDao.find("from User where user='" + userName + "'");
        if (list == null || list.size() < 1) {
            return null;
        }
        User user = list.get(0);
        return user;
    }

    /**
     * 在主题表中插入一个新的User对象
     *
     * @param bean
     */
    public void insert(User bean) {
        baseDao.create(bean);
    }

    /**
     * 删除一个User记录
     *
     * @param bean
     */
    public void delete(User bean) {
        baseDao.delete(bean);
    }

    /**
     * 修改User记录
     *
     * @param bean
     */
    public void modify(User bean) {
        baseDao.update(bean);
    }
}
